﻿<?php

if ($level != 3) {
	echo "Bạn không có quyền vào trang này.";
	exit();
}

if($search) {

	$sql_where 	= "WHERE user_name LIKE '%".$search."%'";
}
$num = $mysql->query("SELECT * FROM ".$tb_prefix."user $sql_where");
$total = $mysql->num_rows($num);
if($total) {
	$m_per_page = 30;
	if (!$pg) $pg = 1;
	$sql = "SELECT * FROM ".$tb_prefix."user $sql_where ORDER BY user_id DESC LIMIT ".(($pg-1)*$m_per_page).",".$m_per_page;
	$query = $mysql->query($sql);
		while($row = $mysql->fetch_array($query)) {
			$user_ID	=	$row['user_id'];
			$user_NAME	=	$row['user_name'];
			$user_LEVEL	=	m_user_level($user_ID);
			$view_pages 	= 	admin_viewpages($total,$m_per_page,$pg);	
			$user_HTML .=	"<tr><td><input class=checkbox type=checkbox id=checkbox onclick=docheckone() name=checkbox[] value=$user_ID></td><td class=fr><a href='?act=user&mode=edit&id=".$user_ID."'><b>".$user_NAME."</b></a></td><td class=fr_2 align=center>".$user_LEVEL."</td></tr>";
		}
}
if(!$total) {
	$user_HTML = "<tr><td></td><td align=center>Chưa có User</td></tr>";
}
elseif ($_POST['do']) {
	$arr = $_POST['checkbox'];
	if (!count($arr)) die('');
	if ($_POST['selected_option'] == 'del') {
		$in_sql = implode(',',$arr);
		$mysql->query("DELETE FROM ".$tb_prefix."user WHERE user_id IN (".$in_sql.")");
		echo "<script language='JavaScript'>{ window.parent.location='?act=list_user' }</script>";
	}
}
include("templates/list_user.html");
?>
